/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package xmarti.vacaxm.test;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import xmarti.vacaxm.beans.maintenance.*;
import xmarti.vacaxm.beans.sequence.*;
import xmarti.vacaxm.exception.ExceptionHibernateVacaxm;
import xmarti.vacaxm.model.ModelSequence;

import xmarti.vacaxm.utils.Utils;


/**
 *
 * @author xmarti
 */
public class testSequenceType {
    
    
    public static void main(String[] args) {
        //<list-index base="1" column="idOrder"></list-index>
   //    addSequenceType();
  //      updateSequenceType();
           //selectSequenceType();
         deleteSequenceType();
//        <many-to-one name="sequenceType" class="xmarti.vacaxm.beans.sequence.SequenceType"  fetch="join" >
//            <column name="idSequenceType"/>
//    </many-to-one>
                
     
      //  deleteStateDefault();
       
        
   }
    
   private static void addSequenceType(){
       ModelSequence model=new ModelSequence();
        SequenceType St = new SequenceType("Gestació","Cicle Gestació");
        StateDefault stateDefault1,stateDefault2,stateDefault3;
        
        try {
            
           
           St.setDescription("Cicle Gestació Update");

            List <State>states= model.getListState();
            stateDefault1 = new StateDefault(1,1,states.get(0),St);
            stateDefault2 = new StateDefault(2,2,states.get(1),St);
            stateDefault3 = new StateDefault(3,3,states.get(2),St);
            St.getStates().add(stateDefault1);
            St.getStates().add(stateDefault2);
            St.getStates().add(stateDefault3);
            
          model.add(St);
            //St.getStates().remove(1);
//            for(StateDefault st:St.getStates()){
//                if (st.getOrder()==1) 
//                    st.setOrder(2);
//                else if(st.getOrder()==2)
//                    st.setOrder(1);
//            } 
         
        //    model.update(St);
//            List <State>states= model.getListState();
//            stateDefault1 = new StateDefault(1,states.get(0),St);
//            stateDefault2 = new StateDefault(2,states.get(1),St);
//            stateDefault3 = new StateDefault(3,states.get(2),St);
//            St.getStates().add(stateDefault1);
//            St.getStates().add(stateDefault2);
//            St.getStates().add(stateDefault3);
//            model.add(St);
//            for (StateDefault sD:St.getStates()){
//                model.add(sD);
//            }
//            
            
            
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }   
   }
    private static void updateSequenceType(){
        ModelSequence model=new ModelSequence();
        SequenceType St = new SequenceType("Gestació","Cicle Gestació");
        StateDefault stateDefault1,stateDefault2,stateDefault3;
        
        try {
            List<SequenceType> sequences=model.getListSequencesType();
            St= sequences.get(0);
            St.setDescription("Cicle Gestació Update1");

//            List <State>states= model.getListState();
//            stateDefault1 = new StateDefault(1,states.get(2),St);
            
           // St.getStates().add(stateDefault1);
            
          //  stateDefault1 = St.getStates().get(1);
          // model.delete(St);
            //St.getStates().remove(1);
            for(StateDefault st:St.getStates()){
                if (st.getOrder()==1) 
                    st.setOrder(15);
                else if(st.getOrder()==2)
                    st.setOrder(20);
            } 
         
           model.update(St);
//            List <State>states= model.getListState();
//            stateDefault1 = new StateDefault(1,states.get(0),St);
//            stateDefault2 = new StateDefault(2,states.get(1),St);
//            stateDefault3 = new StateDefault(3,states.get(2),St);
//            St.getStates().add(stateDefault1);
//            St.getStates().add(stateDefault2);
//            St.getStates().add(stateDefault3);
//            model.add(St);
//            for (StateDefault sD:St.getStates()){
//                model.add(sD);
//            }
//            
            
            
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }
         }  
    
    private static void selectSequenceType(){
        ModelSequence model=new ModelSequence();
            
        List<SequenceType> sequences;
        try {
            sequences = model.getListSequencesType();
            SequenceType    St= sequences.get(0);
            for(StateDefault s: St.getStates()){
                System.out.println(s.getOrder());
            }
            
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }
        
            
    }
     private static void deleteSequenceType(){
        ModelSequence model=new ModelSequence();
            
        List<SequenceType> sequences;
        try {
            sequences = model.getListSequencesType();
            SequenceType    St= sequences.get(0);
            model.delete(St);
           
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }
        
            
    }
     private static void deleteStateDefault(){
        ModelSequence model=new ModelSequence();
            
        List<SequenceType> sequences;
        try {
            sequences = model.getListSequencesType();
            SequenceType    St= sequences.get(0);
            Object[] lst= St.getStates().toArray();
           if(lst.length>0){
               System.out.println(model.deleteStateDefault((StateDefault) lst[0]));
           }
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }
        
            
    }
     
private static int getMaxId(){
     ModelSequence model=new ModelSequence();
     List<SequenceType> sequences;
     SequenceType    St=null;
        try {
            sequences = model.getListSequencesType();
            St= sequences.get(0);
        } catch (ExceptionHibernateVacaxm ex) {
            Logger.getLogger(testSequenceType.class.getName()).log(Level.SEVERE, null, ex);
        }
     
      return model.maxIdStateDefault(St);
}    
}
